package Controller.StudentServlet;

import Dao.StudentDao;
import bean.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/student_alter")
public class student_alter extends HttpServlet {
    StudentDao studentDao = new StudentDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String oldSno = req.getParameter("oldSno");
        String sno = req.getParameter("sno");
        String sname = req.getParameter("sname");
        String sex = req.getParameter("sex");
        if (sex.length() < 1) {
            sex = null;
        }
        String birthday = req.getParameter("birthday");
        if (birthday.length() < 1) {
            birthday = null;
        }
        String dno = req.getParameter("dep");

        ArrayList<Student> list = studentDao.update(oldSno, sno, sname, sex, birthday, dno);
        req.setAttribute("student_list", list);
        req.getRequestDispatcher("StudentInfoSelect.jsp").forward(req, resp);
    }
}
